<!-- 网络请求 -->
<template>
	<view class="page-demo-request">
		<u-navbar :is-back="true" title="网络请求"></u-navbar>
		<view @click="request('GET')"   class="btn-main inline">GET请求</view>
		<view @click="request('POST')" class="btn-main inline">POST请求</view> 
		<view @click="upload"  class="btn-main inline">批量上传</view> 
		
	</view>
</template>

<script>
export default {
	data() {
		return { 
			options:{},
			upload_local:[],
			upload_success:[],
		}
	}, 
	onLoad(options) {
		this.options=options;
	},
	onShareAppMessage(res){
		return {
			title: '',
			path:"/pages/index/index"
		}
	},
	onShow(){},
	onReachBottom(){},
	onHide(){}, 
	onReady(){},
	methods: {
		request:function(method){
			var _this=this;
			this.$api.request("/api/goods/search",{ 
				method:method,
				data:{page:1,per_page:20,keyword:"便宜"}
			}).then((res)=>{
				
			}).catch((err)=>{
				console.log("错误:",err);
			})
		}, 
		upload:function(){
			//批量上传
			var _this=this;
			uni.chooseImage({
				count:9,
				success(res){
					_this.$showLoading("上传中");
					_this.$api.upload('/api/attachment/upload',res.tempFilePaths).then((res)=>{
						_this.$hideLoading()
						console.log("上传成功",res);
						//下一步处理提交格式，提交表单
						
					}).catch((err)=>{
						_this.$hideLoading()
						console.log("上传终止",err)
					})
				}
			}) 
		} 
	}
}
</script>

<style lang="scss">
	.page-demo-request{ 
		text-align: left;
		.btn-main{
			width:40vw ;
			margin:30upx 5vw;
		}
	}
</style>
